#include "frame_src_composite.h"
#include <stdio.h>

CFrameSrcComposite::CFrameSrcComposite()
{

}
CFrameSrcComposite::~CFrameSrcComposite()
{

}

void CFrameSrcComposite::Close()
{

}

int CFrameSrcComposite::start()
{
	int ret = 0;
	for (auto it : m_vecComponent) //.begin(); it != m_vecComponent.end(); it++)
	{
		ret = it->start();
	}

	return 0;
}

void CFrameSrcComposite::CFrameSrcComposite::stop()
{
	 int ret = 0;
	 for (auto it : m_vecComponent) //.begin(); it != m_vecComponent.end(); it++)
	 {
		 it->stop();
	 }

	 return ;
}

int CFrameSrcComposite::add(CFrameSrcComonent* pComonet)
{
	for (auto it : m_vecComponent) 
	{
		if (pComonet->get_stream_id() == it->get_stream_id())
		{
			printf("Have same stream ID %d .\n", pComonet->get_stream_id());
			return -1;
		}
	}

	m_vecComponent.push_back(pComonet);
	return m_vecComponent.size();
}

void CFrameSrcComposite::show_log(int stream_id, bool b_show)
{
	for (auto it : m_vecComponent)
	{
		if (it->get_stream_id() == stream_id)
		{
			it->show_log(b_show);
			break;
		}
		if (stream_id == -1)
		{
			it->show_log(b_show);
		}
	}
}

CFrameSrcComonent* CFrameSrcComposite::get_comonent(int stream_id)
{
	for (auto it : m_vecComponent)
	{
		if (it->get_stream_id() == stream_id)
		{
			return it;
		}
	}
	return NULL;
}